/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tracker.stub;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import tracker.entity.CommentsEntity;
import tracker.entity.CommentsEntityFacade;

/**
 *Workshop 
 *Class ID        : SE0691   
 *Student ID      : SE90009
 *Student Name    : Phạm Nguyễn Nhật Trung
 *Due Date        : 12 November 2012
 *I declare that this assignment is my own work
 *in accordance with FPT Policy.
 */
public class CommentsSessionStub {
    CommentsEntityFacade commentsEntityFacade = lookupCommentsEntityFacadeBean();

     public void insert(CommentsEntity entity) {
        commentsEntityFacade.create(entity);
    }

    public CommentsEntity findUserById(int userId) {
        return commentsEntityFacade.find(userId);
    }

    public void deleteById(int userId) {
        CommentsEntity entity = findUserById(userId);
        commentsEntityFacade.remove(entity);
    }

    public void change(CommentsEntity entity) {
        commentsEntityFacade.edit(entity);
    }

    public List<CommentsEntity> findAll() {
        return commentsEntityFacade.findAll();
    }
    
    private CommentsEntityFacade lookupCommentsEntityFacadeBean() {
        try {
            Context c = new InitialContext();
            return (CommentsEntityFacade) c.lookup("java:global/ASG2-Tracker1/ASG2-Tracker1-ejb/CommentsEntityFacade!tracker.entity.CommentsEntityFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

}
